Detecting return-oriented programming payloads by evaluating data for a gadget address space address and determining whether operations associated with instructions beginning at the address indicate a return-oriented programming payload

ABSTRACT

Systems, methods, and media for detecting the presence of return-oriented programming (ROP) payloads are provided, comprising: identifying a potential gadget address space; determining if a piece of the data corresponds to an address of the potential gadget address space; and in response to determining that the piece of the data corresponds to an address of the potential gadget address space: determining whether a plurality of operations, each associated one of a plurality instructions beginning at the address, indicates that an ROP payload is present in the data, and indicating that an ROP payload is present in the data in response to making a determination that a plurality of operations indicates that an ROP payload is present in the data a given number of times.

CROSS REFERENCE TO RELATED APPLICATION

This application is a continuation of U.S. patent application Ser. No. 15/349,445, filed Nov. 11, 2016, now U.S. Pat. No. 10,192,049, which is a continuation of U.S. patent application Ser. No. 14/344,458, filed Mar. 12, 2014, now U.S. Pat. No. 9,495,541, which is a national stage application under 35 U.S.C. § 371 of International Application No. PCT/US2012/055824, filed Sep. 17, 2012, which claims the benefit of U.S. Provisional Patent Application No. 61/535,288, filed Sep. 15, 2011, each of which is hereby incorporated by reference herein in its entirety.

BACKGROUND

The exploitation of memory corruption vulnerabilities in server and client applications has been one of the prevalent means of system compromise and malware infection. By supplying a malicious input to a target application, an attacker can inject and execute arbitrary code, known as shellcode, in the context of a vulnerable process.

The prevalence of code injection attacks has led to the wide adoption of exploit mitigations based on non-executable memory pages, such as Data Execution Prevention (DEP), in recent versions of popular operating systems.

In turn, attackers are increasingly relying on return-oriented programming (ROP) to bypass these protections. ROP allows the execution of arbitrary code on a victim system without the need to inject any code. ROP relies on the execution of code that already exists in the executable address space of a process, but, instead of executing the code of a whole library function, ROP is based on the execution of a combination of tiny code fragments, dubbed “gadgets,” scattered throughout code segments of the process. The execution order of the gadgets is controlled through a sequence of gadget addresses that is part of the attack payload. This means that an attacker can execute arbitrary code on the victim system by injecting only control data.

During an attack, each gadget called by an ROP payload transfers control to the next gadget through an indirect control transfer instruction that reads the sequence of gadget addresses contained in the injected ROP payload.

In order for the ROP payload to be able to control the execution of these gadgets using the gadget addresses stored in the ROP payload, the gadgets selected by the ROP payload are typically stored in non-volatile portion of executable memory space. For example, such a non-volatile portion of executable memory space would typically not be subject to address space layout randomization (ASLR). The executable memory space in which the gadgets are present can be referred to as gadget address space.

An example of an ROP payload and how it controls the execution of gadgets is shown in FIG. 1. As shown, an ROP payload can exist in data memory starting at an address X and each n byte(s) of data can be a new piece of the payload, where n is the address size used in the target system (e.g., such as four bytes). The instruction pointer (EIP) and the stack pointer (ESP) of the target system can be controlled by the ROP payload to cause it to call the desired gadgets.

More particularly, for example, initially, EIP and ESP may be initialized with values of 070072F7 and a memory address of X+n*1 as shown in FIG. 1. Any suitable mechanism can be used to give EIP and ESP these values. For example, a stack pivot instruction sequence can be used to set EIP and ESP.

This will cause the first gadget call (marked “1st” on the right side of FIG. 1) to occur. As shown, during this call, a “pop eax” instruction and a “ret” instruction are executed. The “pop eax” instruction causes the value (0x0010104) at the address (X+n*1) pointed to by the stack pointer (ESP) to be copied to register EAX, and causes ESP to be incremented by one memory address size (e.g., four bytes, assuming an address size of 32 bits). The “ret” (return) instruction causes the value at the address pointed to by the stack pointer (ESP) to be put into the instruction pointer (EIP) and causes ESP to be incremented by one address size. This “ret” command thus sets up the next gadget call (marked “2nd” on the right side of FIG. 1) at address 070015BB by setting the instruction pointer with the value (070015BB) at the address (X+n*2) pointed to by ESP. Other gadget calls (marked “3rd,” “4th,” and “5th” on the right of FIG. 1) can then be performed in the order specified by the addresses specified in the ROP payload. As can be seen, this allows ESP to be used as an “index” register for transferring control to the desired gadget according to the list of gadget addresses in the ROP payload.

Although gadgets may end with a “ret” instruction as shown in FIG. 1, other indirect control transfer instructions may also be used.

Accordingly, mechanisms for detecting return-oriented programming payloads are desirable.

SUMMARY

Systems, methods, and media for detecting the presence of return-oriented programming (ROP) payloads are provided.

In some embodiments, systems for detecting the presence of return-oriented programming (ROP) payloads are provided, the systems comprising: a hardware processor that: identifies a potential gadget address space; determines if a piece of the data corresponds to an address of the potential gadget address space; and in response to determining that the piece of the data corresponds to an address of the potential gadget address space: determines whether a plurality of operations, each associated one of a plurality instructions beginning at the address, indicates that an ROP payload is present in the data, and indicates that an ROP payload is present in the data in response to making a determination that a plurality of operations indicates that an ROP payload is present in the data a given number of times.

In some embodiments, methods for detecting the presence of return-oriented programming (ROP) payloads are provided, the methods comprising: identifying a potential gadget address space using a hardware processor; determining if a piece of the data corresponds to an address of the potential gadget address space using the hardware processor; and in response to determining that the piece of the data corresponds to an address of the potential gadget address space: determining, using the hardware processor, whether a plurality of operations, each associated one of a plurality instructions beginning at the address, indicates that an ROP payload is present in the data, and indicating, using the hardware processor, that an ROP payload is present in the data in response to making a determination that a plurality of operations indicates that an ROP payload is present in the data a given number of times.

In some embodiments, non-transitory computer-readable media containing computer-executable instructions that, when executed by a processor, cause the processor to perform a method for detecting the presence of return-oriented programming (ROP) payloads are provided, the method comprising: identifying a potential gadget address space; determining if a piece of the data corresponds to an address of the potential gadget address space; and in response to determining that the piece of the data corresponds to an address of the potential gadget address space: determining whether a plurality of operations, each associated one of a plurality instructions beginning at the address, indicates that an ROP payload is present in the data, and indicating that an ROP payload is present in the data in response to making a determination that a plurality of operations indicates that an ROP payload is present in the data a given number of times.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is an illustration of a return-oriented programming (ROP) payload controlling the execution of gadgets in accordance with the prior art.

FIG. 2 is an example of a process for detecting ROP payloads in accordance with some embodiments.

FIG. 3 is an illustration of example actions that can be performed on data to determine if it includes an ROP payload in accordance with some embodiments.

FIG. 4 is a diagram of an example of hardware that can be used for detecting ROP payloads in accordance with some embodiments.

DETAILED DESCRIPTION

Systems, methods, and media for detecting the presence of return-oriented programming (ROP) payloads are provided.

In some embodiments, these mechanisms can identify ROP payloads in data such as network traffic or process memory buffers. These mechanisms can identify ROP payloads by speculatively driving the execution of code that already exists in the address space of a targeted process according to the data. For example, a code emulator can be used to speculatively execute code fragments (gadgets) that exist in the address space of the targeted process at valid memory addresses that are found in the data. If a call to a memory address found in the data causes a threshold number of unique gadget executions to occur, the data can be identified as containing an ROP payload.

In some embodiments, mechanisms for detecting the presence of ROP payloads can be implemented as part of, or in addition to, a shellcode detector that uses a CPU emulator to identify the execution behavior of various shellcode types using any suitable runtime heuristics. For example, in some embodiments, these mechanisms can be implemented as part of, or in addition to, the Nemu shellcode detector or the ShellOS shellcode detector.

Turning to FIG. 2, a process 200 that can be used to identify ROP payloads in accordance with some embodiments is shown. As illustrated, after process 200 begins at 202, the process identifies one or more potential gadget address spaces that may be used by an ROP payload at 204. These one or more gadget address spaces can be identified in any suitable manner. For example, in some embodiments, these gadget address spaces can be identified as being executable memory space that has non-volatile code (e.g., code not subject to ASLR) contained therein. As another example, in some embodiments, multiple gadget address spaces can be identified for one or more gadget address spaces or one or more applications. As yet another example, in some embodiments, multiple gadget address spaces can be identified for different versions of the same code, for different states of the same code (e.g., where the code changes from time to time, such as when using demand dynamic link libraries), for different memory layouts of the same code, for different contexts of the same code when used with different applications, etc.

Next, at 206, a virtual address space of an emulator is initialized with a snapshot of the process memory from an instance (e.g., such as a real instance) of identified one or more gadget address spaces. In some embodiments, different page tables can be maintained in the emulator to allow data to be checked for potential ROP payloads against multiple gadget spaces at the same time.

A first piece of data is next selected at 208. The data can be from any suitable source and can be in any suitable format. For example, the data can be from memory, from a buffer, from streaming content, from a storage device, from a file, from a message, etc. As another example, the data can be stored in groups of any suitable number of bytes (such as four), or bits (such as 32), can be ordered in any suitable arrangement (e.g., such as “little endian” or “big endian”), etc. As described below, the data can be stored in such a way to identify what is “original” data (i.e., data that has not be altered during execution of any gadgets) and non-original data, in some embodiments.

Process 200 then determines whether the value of the selected data corresponds to an address in any of the one or more address spaces of the emulator. For example, as shown in FIG. 3(a), one piece of data 302 has a value of “0072F741,” which does not correspond to a valid address in gadget address space 304. As another example, as shown in FIG. 3(b), another piece of data 306 has a value of “070072F7,” which does correspond to an address in gadget address space 304, as shown by detailed portion 308.

If process 200 determines that the value of the selected data does not correspond to a valid address in any of the one or more address spaces, then the process selects the next piece of data at 212. The next piece of data can be selected in any suitable manner. For example, the next piece of data can be selected by moving a selection window around multiple bytes by one byte. For example, as shown in FIGS. 3(a) and 3(b), when selecting the next piece of data, a window 310 selecting four bytes as a piece of data can be moved one byte to form a new window 312 selecting a different combination of four bytes as a piece of data.

Otherwise, if process 200 determines that the value of the selected data does correspond to a valid address in any of the one or more gadget address spaces, the process then attempts to beginning executing code at this address in the corresponding one or more gadget address spaces using the emulator at 214. This attempt can begin by setting EIP to the value of the selected data and by setting ESP to point to the next piece of data (e.g., as if the next piece of data were selected as described above in connection with 212). For example, as illustrated in FIG. 3(b), EIP can be set to “070072F7” and ESP can be set to point to the next piece of data.

As described above, this will cause a first gadget call to occur. During this call, a “pop eax” instruction and a “ret” instruction are executed. The “pop eax” instruction causes the value (0x0010104) at the address pointed to by the stack pointer (ESP) to be copied to register EAX, and causes ESP to be incremented by one memory address size (e.g., four bytes, as shown). The “ret” (return) instruction causes the value at the address pointed to by the stack pointer (ESP) to be put into the instruction pointer (EIP) and causes ESP to be incremented by one address size. This “ret” command thus sets up the next gadget call at address 070015BB by setting the instruction pointer with the value (070015BB) at the address then pointed to by ESP. As can be seen, this allows ESP to be used as an “index” register for transferring control to the desired gadget according to the list of addresses in the ROP payload.

In some embodiments, before attempting to execute instructions at an address in the gadget address space corresponding to a value of data, a determination can be made as to whether the address has been previously identified as corresponding to a gadget. If not, then 214 can be skipped and process 200 can branch directly to 224 (not shown in FIG. 2). Otherwise, 214 can be performed as described herein. Any suitable mechanism can be used to identify an address as corresponding to a gadget and to determine if an address has been previously identified as corresponding to a gadget.

In some embodiments, the emulator can allow the execution of the gadgets to continue as long as the instructions in the one or more gadgets manipulate the stack pointer correctly, and can terminate the execution for any one or more of the following reasons: i) a gadget transfers control to an invalid address; ii) the emulator encounters an invalid or privileged instruction; iii) the number of executed instructions in the current gadget reaches a certain threshold; or iv) the total number of executed instructions reaches an overall execution threshold.

In order to determine whether conditions iii) or iv) are present, the emulator can count the number of gadget instructions executed in the present gadget, as well as the total number of instructions executed in the present attempt to execute gadget code, that are executed by the emulator at 214 in some embodiments.

As shown in FIG. 2, process 200 can test for an invalid execution address at 216. Any suitable test for identifying an invalid execution address can be used in some embodiments. For example, the process can identify an invalid execution address if EIP is set to an address protected by DEP, to an address only accessible by the kernel, etc. If an invalid execution address is reached, then process 200 can branch to 224 to determine whether the end of the data has been reached as described below.

Otherwise, process 200 can branch to 218 where it can test for invalid or privileged instructions. Any suitable test for identifying invalid or privileged instructions can be used in some embodiments. For example, a random address in a benign input may fall into the middle of an actual instruction in one of the code segments and therefore be invalid. That byte may alternatively correspond to an opcode of a privileged instruction that only the kernel is allowed to execute. If an invalid or privileged instruction is reached, then process 200 can branch to 224 to determine whether the end of the data has been reached as described below.

Otherwise, process 200 can branch to 220 where it can determine whether the count of number of gadget instructions executed in the present gadget has reached and/or exceeded a threshold. This test can help distinguish between random code executions and gadget executions due to an ROP payload. In some cases, the typical size of gadgets used in Turing-complete implementations, as well as in typical exploits, ranges between 2-5 instructions, while the largest number of executed instructions in a single gadget may only be 10 instructions. In some embodiments, a threshold for the count of the number of gadget instructions executed in the present gadget can be set to 32 instructions or any other suitable number of instructions (e.g., such as less than 32 instructions). If the count of the number of gadget instructions executed in the present gadget has reached and/or exceeded the threshold, then process 200 can branch to 224 to determine whether the end of the data has been reached as described below.

Otherwise, process 200 can branch to 222 where it can determine whether the count of the total number of instructions executed in the present attempt has reached and/or exceeded a threshold. This test can ensure, for example, that the execution will stop in case the flow of control has been “trapped” into a loop or an overly long straight-through code path. Any suitable threshold can be used in some embodiments. For example, in some embodiments the threshold can be set to 500, 4096, and/or any other suitable value. If the count of the total number of instructions executed in the present attempt has reached and/or exceeded a threshold, then process 200 can branch to 224 to determine whether the end of the data has been reached as described below.

As described above, if it is determined at 216, 218, 220, or 224 that invalid execution address has been identified, that an invalid or privileged instruction has been identified, that the count of the number of executed instruction for the present gadget has reached a threshold, or that the count of the total number of instructions executed in the present attempt has reached a threshold, respectively, process 200 will branch to 224 where it can determine whether it is at the end of the data. This determination can be made in any suitable manner. For example, in some embodiments, the processor can determine that it is at the end of the data when it has reached a certain memory address, when a stream of data has stopped, when it has reached the end of a file, etc. If process 200 determines that it is not at the end of the data, then the process can select the next piece of data as described above in connection with 212. Otherwise, process 200 can identify the data as not containing an ROP payload at 234 and end at 236.

If at 222, however, it is determined that the count of the total number of instructions executed in the present attempt is below a threshold, then process 200 can determine at 226 whether one or more operations that indicates that an intentional execution of gadgets according to an ROP payload has taken place. Any suitable operation(s) may be used to indicate that an intentional execution of gadgets according to an ROP payload has taken place in some embodiments. For example, in some embodiments, an operation that distinguishes between accidental execution of random instruction sequences and intentional execution of gadgets according to an ROP payload can be used in some embodiments.

In accordance with some embodiment, the determination at 226 can be made using any suitable runtime heuristic for identifying execution behavior of an ROP payload. For example, in some embodiments, an indirect control transfer instruction that is controlled by original data (i.e., the original data of a suspected ROP payload) can be an operation that indicates that an intentional execution of gadgets according to an ROP payload has taken place.

For example, as described above in connection with FIG. 1, the “ret” (return) instruction at the end of the first gadget call (marked “1st” on the right side of FIG. 1) causes the value at the address pointed to by the stack pointer (ESP) to be put into the instruction pointer (EIP) and causes ESP to be incremented by one address size. This “ret” command thus sets up the next gadget call (marked “2nd” on the right side of FIG. 1) at address 070015BB (which is specified in the original data) by setting the instruction pointer with the value (070015BB) at the address (X+n*2) of the original data pointed to by ESP. This “ret” instruction can thus be an operation that indicates that an intentional execution of gadgets according to an ROP payload has taken place.

As another example, in some embodiments, if, during the execution of an instruction sequence, a “jmp eax” instruction transfers control to another valid location in the gadget space, but the value of EAX has not been loaded from the data, then this sequence can be identified as not being such an operation.

As yet another example, consider a relative call instruction that transfers control a few bytes further from a current location of EIP, followed at some point by a “ret” instruction. In this case, the “ret” instruction would not denote such an operation (although it reads an address from the payload and jumps to it), because the value read is not the original value that existed at that location of the data, but is instead the return address pushed at runtime by the call instruction.

If it is determined at 226 that an operation that indicates that an intentional execution of gadgets according to an ROP payload has not taken place, then process 200 can loop back to 214 to continue attempting to execute instructions in the one or more gadget address space(s).

Otherwise, process 200 can increment the gadget count at 228 and then determine, at 230, whether the gadget count has reached and/or exceeded a threshed. This gadget count can be incremented in any suitable manner. For example, in some embodiments, the gadget count can be incremented upon the completion of each gadget. As another example, in some embodiments, the gadget count can be incremented only upon the completion of each unique gadget (e.g., a gadget that has not previously been executed). As yet another example, in some embodiments, the gadget count can be incremented only upon the completion of each unique gadget having two (or any other suitable number) or more instructions. Any suitable threshold can be used in some embodiments. For example, a threshold of four to eight (e.g., six) unique gadgets can be used in some embodiments.

If it is determined at 230 that the gadget count has not reached and/or exceeded the threshold, then process 200 can loop back to 214 to continue attempting to execute instructions in the one or more gadget address space(s). Otherwise, process 200 can identify the data as containing an ROP payload at 232 and end at 236.

In accordance with some embodiments, any suitable hardware and/or software can be used to perform the mechanisms described herein (such as those illustrated in, and described in connection with, FIGS. 1, 2, and 3). For example, a general purpose device such as a computer or a special purpose device such as a client, a server, etc. can be used to execute software for performing the mechanisms described herein. Any of these general or special purpose devices, such as device 400 of FIG. 4, can include any suitable components such as a hardware processor 402 (which can be a microprocessor, digital signal processor, a controller, etc.), memory 404, communication interfaces 406, a display interface and display 408, user input devices 410, a database and/or storage 412, a communications bus 414, etc. Communications interfaces 406 can enable the hardware and/or software to communicate with other communications networks (e.g., such as the Internet, wired networks, wireless networks, etc.), other devices, etc. This hardware and/or software can be implemented as part of other equipment or can be implemented as stand-alone equipment. Any of these devices can include an emulator, whether implemented in hardware and/or software.

In some embodiments, any suitable computer readable media can be used for storing instructions for performing the processes described herein. For example, in some embodiments, computer readable media can be transitory or non-transitory. For example, non-transitory computer readable media can include media such as magnetic media (such as hard disks, floppy disks, etc.), optical media (such as compact discs, digital video discs, Blu-ray discs, etc.), semiconductor media (such as flash memory, electrically programmable read only memory (EPROM), electrically erasable programmable read only memory (EEPROM), etc.), any suitable media that is not fleeting or devoid of any semblance of permanence during transmission, and/or any suitable tangible media. As another example, transitory computer readable media can include signals on networks, in wires, conductors, optical fibers, circuits, any suitable media that is fleeting and devoid of any semblance of permanence during transmission, and/or any suitable intangible media.

Although the invention has been described and illustrated in the foregoing illustrative embodiments, it is understood that the present disclosure has been made only by way of example, and that numerous changes in the details of implementation of the invention can be made without departing from the spirit and scope of the invention, which is limited only by the claims which follow. Features of the disclosed embodiments can be combined and rearranged in various ways. 

What is claimed is:
 1. A system for detecting the presence of a return-oriented programming (ROP) payload in data, comprising: a hardware processor that: identifies a potential gadget address space; determines if a piece of the data corresponds to an address of the potential gadget address space; and in response to determining that the piece of the data corresponds to an address of the potential gadget address space: determines whether a plurality of operations, each associated one of a plurality instructions beginning at the address, indicates that an ROP payload is present in the data, and indicates that an ROP payload is present in the data in response to making a determination that a plurality of operations indicates that an ROP payload is present in the data a given number of times. 